/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package towerdefence.view;

import com.sun.opengl.util.texture.Texture;
import java.awt.Color;
import javax.media.opengl.GL;
import net.phys2d.math.ROVector2f;
import net.phys2d.raw.shapes.Box;
import net.phys2d.raw.shapes.Shape;
import towerdefence.model.Block;
import towerdefence.model.blocks.SteelBlock;
import towerdefence.model.blocks.StoneBlock;
import towerdefence.model.blocks.StyrofoamBlock;
import static javax.media.opengl.GL.*;

/**
 *
 * @author Andreas
 */
public class GLBlockRenderer {

    private static float[] styrofoamColor = Color.LIGHT_GRAY.getRGBComponents(null);
    private static float[] standardColor = Color.WHITE.getRGBComponents(null);

    public static void drawBlock(GL gl, Block block) {
        float[] color;
        if (block instanceof StyrofoamBlock) {
            color = styrofoamColor;
        } else {
            color = standardColor;
        }
        drawBlock(gl, block, color);
    }

    public static void drawBlock(GL gl, Block block, float[] color) {
        
        Texture texture = null;
        if(block instanceof StyrofoamBlock) {
            texture = TextureHandler.getTexture(TextureHandler.BLOCK_STYROFOAM);
        }
        else if(block instanceof SteelBlock) {
            texture = TextureHandler.getTexture(TextureHandler.BLOCK_STEEL);
        }
        else if(block instanceof StoneBlock) {
            texture = TextureHandler.getTexture(TextureHandler.BLOCK_STONE);
        }
        drawBlock(gl, block, color, texture);
    }

    public static void drawBlock(GL gl, Block block, float[] color, Texture texture) {
        Shape shape = block.getShape();

        if (shape instanceof Box) {
            GLBoxRenderer.drawBox(gl, block, (Box) shape, color, texture);
        }
    }
}
